#!/bin/bash
packet_num=0
for packet in libaio numactl
do
rpm -qa|grep $packet
if [[ $? -gt 0 ]]
then
packet_num=${packet_num+1}
fi
done
echo $packet_num
if [[ $packet_num -gt 0 ]]
then
yum install -y libaio numactl
fi
cPWD=`pwd`
echo $PWD > /tmp/mysql.log
groupadd -r mysql
useradd -r -g mysql -s /sbin/nologin mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql

mkdir -p /data/tools
cd /data/tools
echo 'downloading...'
wget -c  https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-5.7/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz || exit 1

tar zxvf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz -C /usr/local
ln -s /usr/local/mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql-5.7.24-linux-glibc2.12-x86_64
rm -f /etc/my.cnf
cp conf/my.cnf /etc/my.cnf
cd /usr/local/mysql
./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql  --datadir=/data/mysql \
--explicit_defaults_for_timestamp
#bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/
ln -s /usr/local/mysql/bin/mysqlbinlog /usr/bin
#ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
#ln -s /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
cd $cPWD
echo `pwd` >> /tmp/mysql.log
service mysqld start
#/usr/local/mysql/bin/mysqld_safe --user=mysql &
/usr/local/mysql/bin/mysqladmin -u root password 'root'
ln -s /usr/local/mysql/include /usr/include/mysql
echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
ldconfig
ldconfig -v | grep mysql
#
#/usr/local/mysql/bin/mysql_secure_installation
{
mysql -uroot -proot -e "delete from mysql.user where user='';FLUSH PRIVILEGES;"
mysql -uroot -proot -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
mysql -uroot -proot -e "DROP DATABASE test;DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';"
mysql -uroot -proot -e "FLUSH PRIVILEGES;"
} > /dev/null 2>&1
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
service mysqld restart